package net.soevar.database.model;

import java.util.Date;
import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(schema = "public", name = "ath_user")
public class AthUser implements Serializable {

	private static final long serialVersionUID = -5641345668540842291L;
	private String userId;
	private String userPassword;
	private String userNama;
	private AthRole userRole;
	private Boolean isEncripted;
	private Boolean statusRoot;
	private Boolean statusAktif;
	private Boolean statusApproval;
	private Date lastLogin = new Date();
	private Jobseeker jobseeker;
	private String dirubahOleh;
	private Date dirubahTanggal = new Date();

	@Id
	@Column(name = "user_id", unique = true, nullable = false, length = 255)
	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	@Column(name = "user_password", nullable = true, length = 255)
	public String getUserPassword() {
		return userPassword;
	}

	public void setUserPassword(String userPassword) {
		this.userPassword = userPassword;
	}

	@Column(name = "user_nama", nullable = true, length = 255)
	public String getUserNama() {
		return userNama;
	}

	public void setUserNama(String userNama) {
		this.userNama = userNama;
	}

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@Fetch(FetchMode.SELECT)
	@JoinColumn(name = "user_role", nullable = true)
	public AthRole getUserRole() {
		return userRole;
	}

	public void setUserRole(AthRole userRole) {
		this.userRole = userRole;
	}

	@Column(name = "is_encripted")
	public Boolean getIsEncripted() {
		return isEncripted;
	}

	public void setIsEncripted(Boolean isEncripted) {
		this.isEncripted = isEncripted;
	}

	@Column(name = "status_root")
	public Boolean getStatusRoot() {
		return statusRoot;
	}

	public void setStatusRoot(Boolean statusRoot) {
		this.statusRoot = statusRoot;
	}

	@Column(name = "status_aktif")
	public Boolean getStatusAktif() {
		return statusAktif;
	}

	public void setStatusAktif(Boolean statusAktif) {
		this.statusAktif = statusAktif;
	}

	@Column(name = "status_approval")
	public Boolean getStatusApproval() {
		return statusApproval;
	}

	public void setStatusApproval(Boolean statusApproval) {
		this.statusApproval = statusApproval;
	}

	@Column(name = "last_login")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getLastLogin() {
		return lastLogin;
	}

	public void setLastLogin(Date lastLogin) {
		this.lastLogin = lastLogin;
	}

	@ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(name = "jobseeker", nullable = true)
	public Jobseeker getJobseeker() {
		return jobseeker;
	}

	public void setJobseeker(Jobseeker jobseeker) {
		this.jobseeker = jobseeker;
	}

	@Column(name = "dirubah_oleh", length = 100)
	public String getDirubahOleh() {
		return dirubahOleh;
	}

	public void setDirubahOleh(String dirubahOleh) {
		this.dirubahOleh = dirubahOleh;
	}

	@Column(name = "dirubah_tanggal")
	@Temporal(TemporalType.TIMESTAMP)
	public Date getDirubahTanggal() {
		return dirubahTanggal;
	}

	public void setDirubahTanggal(Date dirubahTanggal) {
		this.dirubahTanggal = dirubahTanggal;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((userId == null) ? 0 : userId.hashCode());
		result = prime * result
				+ ((userRole == null) ? 0 : userRole.hashCode());
		return result;
	}

}
